# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pkg-config
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.29.2
pkgrel=3
pkgdesc="A system for managing library compile/link flags (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.freedesktop.org/wiki/Software/pkg-config/"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://pkgconfig.freedesktop.org/releases/${_realname}-${pkgver}.tar.gz
        0001-fix-double-slash-in-test.patch
        0010-expand-paths.mingw.patch
        0011-platform-dependent-separator-and-adjustable-prefix.mingw.patch
        1001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch
        1003-g_abort.all.patch
        1005-glib-send-log-messages-to-correct-stdout-and-stderr.patch
        1017-glib-use-gnu-print-scanf.patch
        1024-return-actually-written-data-in-printf.all.patch
        1030-fix-stat.all.patch
        1031-fix-glib-gettext-m4-error.patch)
sha256sums=('6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591'
            '85c031dec59a82f40cfad5223c1a440c1c633dcf9beb6feddf679af1d41bb8db'
            'fe8f71995d56fd3d69d169031e54c91b9b01c74995143664a2455ec21c7377e1'
            'e895eddd041d2c05abd15789cf2895f35e339702f36af34206a62241cdb42637'
            'ef81e82e15fb3a71bad770be17fe4fea3f4d9cdee238d6caa39807eeea5da3e3'
            '3a6ef5b99f76504e58297d196d129df40f86f9b608dbc4f20cf135680ff558ab'
            '94b705382b405bf8eae51c4f82afbf819b6caa5b3e51512be18c870b79947f88'
            'bd2a8a53f320a4fe7d45d75fe3a4b16882dc27597618759a44e791ae831efccb'
            '8421aed91370cf8eb5f0dde443bbc63e5dd4c238c586053eab4fbbae2e005d8c'
            '9ba68777f48816cbee154084c10d0d577a021ef406606d5c2d230761cf82b66b'
            '9ee4a55eac8ec5a07abe69fd17b521a4013d06ad8ac9d27cb3a94d86c358e03e')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-fix-double-slash-in-test.patch
  patch -p1 -i ${srcdir}/0010-expand-paths.mingw.patch
  patch -p1 -i ${srcdir}/0011-platform-dependent-separator-and-adjustable-prefix.mingw.patch

  sed -i check/simple.pc -e "s,prefix=/usr,prefix=${MINGW_PREFIX},"

  cd glib

  patch -Np1 -i "${srcdir}/1001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch"
  patch -Np1 -i "${srcdir}/1003-g_abort.all.patch"
  patch -Np1 -i "${srcdir}/1005-glib-send-log-messages-to-correct-stdout-and-stderr.patch"
  patch -Np1 -i "${srcdir}/1017-glib-use-gnu-print-scanf.patch"
  patch -Np1 -i "${srcdir}/1024-return-actually-written-data-in-printf.all.patch"
  patch -Np1 -i "${srcdir}/1030-fix-stat.all.patch"
  patch -Np1 -i "${srcdir}/1031-fix-glib-gettext-m4-error.patch"

  cd ..

  autoreconf -fi
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-internal-glib \
    --disable-indirect-deps \
    --with-default-prefix-for-default-paths=${MINGW_PREFIX}

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make check
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
